package src.分治法求众数;

import org.junit.Test;

import java.util.*;
import java.util.stream.Collectors;

/**
 * @author liugongding
 * @description:
 * @date 2022/3/11 11:58 AM
 */
public class Solution2 {
    private Map<Integer, Integer> countNums(int[] nums) {
        Map<Integer, Integer> counts = new HashMap<>();
        for (int num : nums) {
            if (!counts.containsKey(num)) {
                counts.put(num, 1);
            } else {
                counts.put(num, counts.get(num) + 1);
            }
        }
        return counts;
    }

    public int majorityElement(int[] nums) {
        Map<Integer, Integer> counts = countNums(nums);
        List<Integer> collect = counts.values().stream().collect(Collectors.toList());

        //Map.Entry<Integer, Integer> majorityEntry = null;
        //for (Map.Entry<Integer, Integer> entry : counts.entrySet()) {
        //    if (majorityEntry == null || entry.getValue() >= majorityEntry.getValue()) {
        //        majorityEntry = entry;
        //    }
        //}
        //return majorityEntry.getKey();
        return 0;
    }

    @Test
    public void test(){
    }

}
